package com.preparation.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.preparation.domain.Category;
import com.preparation.dto.R;
import com.preparation.mapper.*;
import com.preparation.service.ICategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
public class CategoryServiceImpl extends ServiceImpl<CategoryMapper, Category> implements ICategoryService {
    @Autowired
    private CategoryMapper categoryMapper;


    // 添加类别
    @Override
    public R addCategory(Category category) {
        Category res = categoryMapper.getByCname(category.getCategoryName());
        if(res != null){
            return R.error(409, "该类别已存在！");
        }

        category.setCreateTime(new Date());

        return categoryMapper.insert(category) > 0 ? R.success("添加成功") : R.error();
    }
}
